package com.app.shop.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.app.shop.controller.system.BaseController;
import com.app.shop.entity.WgMember;
import com.app.shop.entity.query.WgMemberQuery;
import com.app.shop.entity.show.BaseShow;
import com.app.shop.entity.show.WgMemberShow;
import com.app.shop.service.shop.WgMemberService;
import com.app.shop.util.ApiRest;
import com.app.shop.util.ClassUtil;
import com.app.shop.util.Constant;
import com.github.pagehelper.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * 订单服务类Controller
 *
 * @author  chen li wei
 * @version 21:14 2019-5-10
 */
@Controller
@RequestMapping(value = "/wgMember")
public class WgMemberController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(WgMemberController.class);
    @Autowired
    WgMemberService sysMemberService;

    /**
     * 查询订单列表
     * @param sysMemberQuery 查询订单参数
     * @return 返回订单列表
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(value = "/getMemberList")
    public ApiRest getDictList(@RequestBody WgMemberQuery sysMemberQuery) {
        log.debug(JSONObject.toJSON(sysMemberQuery).toString());
        //查询
        Page<WgMember> sysMemberList=sysMemberService.getWgMemberList(sysMemberQuery);
        //查询结果对象置换
        List<WgMemberShow> resList=new ArrayList<WgMemberShow>();
        WgMemberShow sysMemberShow;
        //数据转换
        for(WgMember sysMember:sysMemberList){
            sysMemberShow=new WgMemberShow();
            try {
                ClassUtil.fatherToChild(sysMember,sysMemberShow);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //码表值补全
            sysMemberShow.dataSet();
            resList.add(sysMemberShow);
        }
        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE,
                new BaseShow(sysMemberList.getPageNum(), sysMemberList.getPageSize(), sysMemberList.getTotal(), sysMemberList.getPages(), resList));    }

 
                

}
